import requests

 	result = requests.get('https://www.qschina.cn/sites/default/files/qs-ranking-data/cn/2005378.txt')
 	result = requests.get('https://www.qschina.cn/university-rankings/university-subject-rankings/2020/communication-media-studies')
 	
 	# 生成历年数据入口地址
 	def urls(start,end):
 	    for i in range(start,end+1):
 	        url = 'https://www.qschina.cn/university-rankings/university-subject-rankings/2020/communication-media-studies
 	        '
 	        result = request.get(url)
 	        dataUrl = getUrl(result.text)
 	        resource[i] = dataUrl
 	    return resource
 	
 	    # print(urls(2017,2020)) 
 	
 	# 获取数据入口地址
 	
 	def getTitle(content):
 	    pattern = re.compile('<a.*?>(.*?)<\\/a>')
 	    result = re.search(pattern, content)
 	    return result.group(1)
 	
 	     print(urls(2017,2020)) 
 	
 	# fo = open("./23/results.txt","w",encoding'utf-8)
 	# fo.write(result.text.encode('utf-8').decode('unicode.escape'))
 	# fo.close()
 	
 	# print(getTitle(result.json()['data'][0]['title']))
 	
 	import csv
 	
 	resources = urls(2017,2020)
 	
 	with open('names.csv', 'w', newline='',encoding='utf-8') as csvfile:
 	    fieldnames = ['name', 'value','date']
 	    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
 	
 	    writer.writeheader()
 	    for year in resources:
 	        result = requests.get(resources[year])
 	
 	    for item in results.json()['data']:
 	        writer.writerow({'name':getTitle(item['title']),'value':item['score'],'date':year})
 	    # writer.writerow({'姓名': 'Baked', '别名': 'Beans'，'年代': '2020'})
 	    # writer.writerow({'姓名': 'Lovely', '别名': 'Spam'，'年代': '2020'})
 	    # writer.writerow({'姓名': 'Wonderful', '别名': 'Spam'，'年代': '2020'})